package com.alameda.controller.user;

import com.alameda.api.user.UserOrganizationService;
import com.alameda.api.user.UserService;
import com.alameda.result.Result;
import com.alameda.user.dto.UserDTO;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * 用户 前端控制层
 *
 * @author Lv
 * @date 2024/2/19
 */
@Api(tags = "用户")
@RestController
@RequestMapping("/user")
public class UserController {

    @Autowired
    private UserService userService;

    /**
     * 获取当前登录用户信息
     *
     * @return
     */
    @ApiOperation("获取当前登录用户信息")
    @PostMapping("/get_user_info")
    public Result<?> getUserInfo() {
        return Result.success(userService.getUserInfo());
    }

    /**
     * 修改用户信息
     *
     * @param userDTO 用户数据传递对象
     * @return
     */
    @ApiOperation("修改用户信息")
    @PostMapping("/edit")
    public Result<?> edit(@RequestBody UserDTO userDTO) {
        return Result.success(userService.edit(userDTO));
    }

    /**
     * 查询用户列表
     *
     * @param userDTO 用户数据传递对象
     * @return
     */
    @ApiOperation("查询用户列表")
    @PostMapping("/load_user")
    public Result<?> loadUser(@RequestBody UserDTO userDTO) {
        return Result.success(userService.loadUser(userDTO));
    }

    @Autowired
    private UserOrganizationService userOrganizationService;

    /**
     * 加载所有子组织下拉框
     *
     * @return
     */
    @ApiOperation("加载所有子组织下拉框")
    @PostMapping("/load_all_son_organization")
    public Result<?> loadAllSonOrganization() {
        return Result.success(userOrganizationService.loadAllSonOrganization());
    }

    /**
     * 导出excel
     *
     * @param userDTO 用户数据传递对象
     */
    @PostMapping("/export")
    public void export(@RequestBody UserDTO userDTO) {
        userService.export(userDTO);
    }
}
